/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Simple (Very stupid) C++ class name demangler
 * \author Antti Maula <antti.maula@tkk.fi>
 */
#ifndef _GIM_UTILS_DEMANGLER_HPP_
#define _GIM_UTILS_DEMANGLER_HPP_

#include <stdio.h>
#include <map>
#include <typeinfo>
#include <string>


#define OWNTYPENAMESTR(xxx) gim::CDemangler::GetDemangledName(typeid((xxx)).name())

namespace gim
{
  class CDemangler
  {
  public:

    /** Get a Demangled name for a C++ class or function.  This
     * function is implemented as a associative map, which is built
     * using an very inefficient method : by calling a system binary
     * to do the real translation. However, this inefficient method is only
     * called once per each function/class name, as the result is then
     * stored to a map for fast referencing.
     *
     * @param[in] aMangledName  Mangled name string to demangle
     * @return                  Demangled name string.
     */
    static const std::string GetDemangledName(const std::string &aMangledName);

  private:
    static std::map<std::string, std::string> iMangledToDemangledMap;
    static std::string ConstructDemangledName(const std::string &aMangled);    
  };
}

#endif
